/*
 * HSVDialog.java
 *
 * Created on Sep 19, 2011, 8:00:06 PM
 */
package com.photoexpert;

import java.awt.Graphics;
import javax.swing.JPanel;

/**
 *
 * @author PANYIXIN
 */
class HSVDialog extends javax.swing.JDialog {

    HSVDialog() {
        super(App.Instance(), true);
        initComponents();
        setLocation(200, 200);
        ((PreviewPane)_previewPane).setOp(null);
        setVisible(true);
    }

    private static class HueCircle extends JPanel {
        @Override
        public void paint(Graphics g) {
            
        }
    }

    private void preview() {
        int hValue = _hSlider.getValue();
        int sValue = _sSlider.getValue();
        int vValue = _vSlider.getValue();
        if(hValue == 0 && sValue == 0 && vValue == 0)
            _op = null;
        else
            _op = new HSVOp(1f, hValue, 1f, sValue, 1f, vValue, null);
        ((PreviewPane)_previewPane).setOp(_op);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        _hSlider = new javax.swing.JSlider();
        _previewLabel = new javax.swing.JLabel();
        _previewPane = PreviewPane.CreateInstance();
        _cancel = new javax.swing.JButton();
        _ok = new javax.swing.JButton();
        _yLabel = new javax.swing.JLabel();
        _iLabel = new javax.swing.JLabel();
        _vSlider = new javax.swing.JSlider();
        _qLabel = new javax.swing.JLabel();
        _sSlider = new javax.swing.JSlider();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("HSV Adjustor");
        setModal(true);
        setResizable(false);

        _hSlider.setMajorTickSpacing(20);
        _hSlider.setMinimum(-100);
        _hSlider.setMinorTickSpacing(10);
        _hSlider.setPaintLabels(true);
        _hSlider.setPaintTicks(true);
        _hSlider.setValue(0);
        _hSlider.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                _hSliderStateChanged(evt);
            }
        });

        _previewLabel.setText("Preview:");

        _previewPane.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        _previewPane.setPreferredSize(new java.awt.Dimension(252, 192));

        javax.swing.GroupLayout _previewPaneLayout = new javax.swing.GroupLayout(_previewPane);
        _previewPane.setLayout(_previewPaneLayout);
        _previewPaneLayout.setHorizontalGroup(
            _previewPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 250, Short.MAX_VALUE)
        );
        _previewPaneLayout.setVerticalGroup(
            _previewPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 190, Short.MAX_VALUE)
        );

        _cancel.setText("Cancel");
        _cancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _cancelActionPerformed(evt);
            }
        });

        _ok.setText("OK");
        _ok.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _okActionPerformed(evt);
            }
        });

        _yLabel.setText("H:");

        _iLabel.setText("S:");

        _vSlider.setMajorTickSpacing(20);
        _vSlider.setMinimum(-100);
        _vSlider.setMinorTickSpacing(10);
        _vSlider.setPaintLabels(true);
        _vSlider.setPaintTicks(true);
        _vSlider.setValue(0);
        _vSlider.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                _vSliderStateChanged(evt);
            }
        });

        _qLabel.setText("V:");

        _sSlider.setMajorTickSpacing(20);
        _sSlider.setMinimum(-100);
        _sSlider.setMinorTickSpacing(10);
        _sSlider.setPaintLabels(true);
        _sSlider.setPaintTicks(true);
        _sSlider.setValue(0);
        _sSlider.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                _sSliderStateChanged(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(_yLabel)
                            .addComponent(_iLabel)
                            .addComponent(_qLabel))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(_vSlider, javax.swing.GroupLayout.DEFAULT_SIZE, 311, Short.MAX_VALUE)
                            .addComponent(_sSlider, javax.swing.GroupLayout.DEFAULT_SIZE, 311, Short.MAX_VALUE)
                            .addComponent(_hSlider, javax.swing.GroupLayout.DEFAULT_SIZE, 311, Short.MAX_VALUE)))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(_previewPane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(_cancel, javax.swing.GroupLayout.DEFAULT_SIZE, 67, Short.MAX_VALUE)
                            .addComponent(_ok, javax.swing.GroupLayout.DEFAULT_SIZE, 67, Short.MAX_VALUE)))
                    .addComponent(_previewLabel))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(_yLabel)
                    .addComponent(_hSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(_iLabel)
                    .addComponent(_sSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(_qLabel)
                    .addComponent(_vSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(_previewLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(_ok)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(_cancel))
                    .addComponent(_previewPane, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void _hSliderStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event__hSliderStateChanged
        preview();
    }//GEN-LAST:event__hSliderStateChanged

    private void _okActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__okActionPerformed
        if(_op != null)
            Implementor.Instance().adjust(_op);
        setVisible(false);
        dispose();
    }//GEN-LAST:event__okActionPerformed

    private void _cancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__cancelActionPerformed
        setVisible(false);
        dispose();
    }//GEN-LAST:event__cancelActionPerformed

    private void _vSliderStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event__vSliderStateChanged
        preview();
    }//GEN-LAST:event__vSliderStateChanged

    private void _sSliderStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event__sSliderStateChanged
        preview();
    }//GEN-LAST:event__sSliderStateChanged

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton _cancel;
    private javax.swing.JSlider _hSlider;
    private javax.swing.JLabel _iLabel;
    private javax.swing.JButton _ok;
    private javax.swing.JLabel _previewLabel;
    private javax.swing.JPanel _previewPane;
    private javax.swing.JLabel _qLabel;
    private javax.swing.JSlider _sSlider;
    private javax.swing.JSlider _vSlider;
    private javax.swing.JLabel _yLabel;
    // End of variables declaration//GEN-END:variables
    private HSVOp   _op;
}
